Skip to content

Option to drop reference level in TreatmentContrast#263

Open
leostimpfle wants to merge 1 commit intomatthewwardrop:mainfrom
leostimpfle:drop_reference_level
Open

Option to drop reference level in TreatmentContrast#263
leostimpfle wants to merge 1 commit intomatthewwardrop:mainfrom
leostimpfle:drop_reference_level

Conversation

@leostimpfle
Copy link
Copy Markdown

This PR illustrates the idea mentioned in #244 (comment) which is motivated by the fixest::i() syntax that gives better control over interactions of factor variables.

The only change is the addition of the attribute drop in TreatmentContrasts which allows the user to specify if the reference level in the contrast encoding should be dropped.

For example,

rng = np.random.default_rng(91)
df = pd.DataFrame(
    {
        "factor1": rng.choice(["a", "b", "c"], 10),
        "factor2": rng.choice([1, 2, 3], 10),
        "y": rng.normal(0, 1, 10),
    },
)

model_matrix(
    "C(factor1, contr.treatment('a', drop=True))",
    data=df,
    ensure_full_rank=False,
)

(cc @s3alfisc)

@matthewwardrop
Copy link
Copy Markdown
Owner

As noted in the issue thread (#244 (comment)) I don't think this actually implements things sufficiently closely to i(). I have the beginnings of a PR on the way, but it would be great to have the approach sanity checked in the issue thread :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants